<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '创建导航';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="cw-nav-index">
    
    <div id="temp-navbar" class="navbar" stcwe="display: none; border: 2px dashed red">
        <ul class="nav nav-tabs">
            <?php
                foreach ($dataProvider->models as $nav){
                    $navlist = "";
                    if($nav->nav_level==1){
                        foreach ($dataProvider->models as $navc){
                            if ($navc->nav_level==2&&$navc->nav_dady==$nav->nav_name){
                                $navlist =$navlist.'<li><a href="'.$navc->nav_link.'">'.$navc->nav_name.'</a></li>';
                            }
                        }
                        echo '<li class="dropdown"><a id="n'.$nav->nav_id.'" class="dropdown-toggle" href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">'.$nav->nav_name.'<span class="caret"></span></a><ul class="dropdown-menu" aria-labelledby="n'.$nav->nav_id.'">'.$navlist.'</ul></li>';
                    }
                }
            ?>
        </ul>
    </div>

    
    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('创建', ['create'], ['class' => 'btn btn-success']) ?>
        <a href="javascript:navbar_show()" class="btn btn-info">展示</a>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'nav_id',
            'nav_name',
            'nav_dady',
            'nav_level',
            'nav_link',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
<script>
document.getElementById('cw-nav').setAttribute('class',"active");
function navbar_show(){
    $('#temp-navbar').show();
    $('.btn-info').html("收起");
    $('.btn-info').attr("href","javascript:navbar_hide()")
}
function navbar_hide(){
    $('#temp-navbar').hide();
    $('.btn-info').html("展示");
    $('.btn-info').attr("href","javascript:navbar_show()")
}
</script>
